import type { PageParam, PageResult } from '@vben/request';

import { requestClient } from '#/api/request';

export namespace InfraDatacenterTableFieldsApi {
  /** 数据中枢字段信息 */
  export interface DatacenterTableFields {
    id: number; // 主键
    tableId?: number; // 数据表ID
    fieldName?: string; // 字段名称
    fieldDesc: string; // 字段描述
    dataType?: string; // 数据类型
    javaType?: string; // Java 属性类型
    javaField?: string; // Java 属性名
    dictType?: string; // 字典类型
    required?: boolean; // 是否必填
    options: string; // 扩展项
    primaryKey?: boolean; // 是否主键
  }
}

/** 查询数据中枢字段分页 */
export function getDatacenterTableFieldsPage(
  data: PageParam,
  desensitize: boolean,
  encrypt: boolean,
) {
  return requestClient.post<
    PageResult<InfraDatacenterTableFieldsApi.DatacenterTableFields>
  >('/infra/datacenter-table-fields/page', data, { desensitize, encrypt });
}

/** 查询数据中枢字段详情 */
export function getDatacenterTableFields(id: number) {
  return requestClient.get<InfraDatacenterTableFieldsApi.DatacenterTableFields>(
    `/infra/datacenter-table-fields/get?id=${id}`,
  );
}

/** 新增数据中枢字段 */
export function createDatacenterTableFields(
  data: InfraDatacenterTableFieldsApi.DatacenterTableFields,
) {
  return requestClient.post('/infra/datacenter-table-fields/create', data);
}

/** 修改数据中枢字段 */
export function updateDatacenterTableFields(
  data: InfraDatacenterTableFieldsApi.DatacenterTableFields,
) {
  return requestClient.put('/infra/datacenter-table-fields/update', data);
}

/** 删除数据中枢字段 */
export function deleteDatacenterTableFields(id: number) {
  return requestClient.delete(`/infra/datacenter-table-fields/delete?id=${id}`);
}

/** 批量删除数据中枢字段 */
export function deleteDatacenterTableFieldsList(ids: number[]) {
  return requestClient.delete(
    `/infra/datacenter-table-fields/delete-list?ids=${ids.join(',')}`,
  );
}

/** 导出数据中枢字段 */
export function exportDatacenterTableFields(params: any) {
  return requestClient.download('/infra/datacenter-table-fields/export-excel', {
    params,
  });
}
/** 获取数据中枢字段数据类型字典 */
export function getDataTypeDict() {
  return requestClient.get<any[]>(
    '/infra/datacenter-table-fields/get-data-type-dict',
  );
}
